<?php
session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin','teacher','student');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';

}


?>


<!--lets get it -->
<? $topid = $_GET['topicid'];

//topic query again
//loop it!
$topicQuery = mysql_query("SELECT * FROM tblfrtopic WHERE topicid = '$topid' ");
//eto n ang loop
	while($row  =  mysql_fetch_array($topicQuery)):
	$topicid = $row['topicid'];
	$title 	 = $row['topictitle'];
	$content = $row['topicontent'];
	$date 	 = $row['topicdate'];
	$createby = $row['createdby'];
	$createid = $row['createbyid'];
	$views 	  = $row['vies'];
	$topiccat = $row['category'];
	
	if($topiccat == 'makabayan'):
		$catlink = 'viewMakabayan';
		$catego = 'Makabayan';
		//Filipino Section
		elseif($topiccat == 'filipino'):
		$catlink = 'viewFilipino';
		$catego = 'Filipino';
		//English Section
		elseif($topiccat == 'english'):
		$catlink = 'viewEnglish';
		$catego = 'English';
		//Math Section
		elseif($topiccat == 'math'):
		$catlink = 'viewMath';
		$catego = 'Math';
		//Science Section
		elseif($topiccat == 'science'):
		$catlink = 'viewScience';
		$catego = 'Science';
		//Others Section
		elseif($topiccat == 'others'):
		$catlink = 'viewOthers';
		$catego = 'Others';
		
endif;
	endwhile;
	
//preview
if(isset($_POST['create']))
{
		$userid = $_SESSION['curuser'];
		$topicid = $_GET['topicid'];
		$replycontent = $_POST['elm1'];
		$replyby = $_SESSION['us'];
		$datetime = date("F j, Y H:i:s");
		
		//replacement words
	 $resultOfRep = mysql_query("SELECT origWord,replaceWord FROM tblreplace") or die(mysql_error()); 
   		

    while($rowRes = mysql_fetch_assoc($resultOfRep))
    {		$repWord = $rowRes['replaceWord'];
			$origWord = $rowRes['origWord'];
          
		  $replycontent = str_ireplace($origWord,$repWord,$replycontent);
		
    }  
   
	 if($replycontent){
			$resInsert = mysql_query("INSERT INTO `tblreplace`(`origWord`,`replaceWord`,`creatorName`,`date`,`fieldName`)
									 VALUES('$origWord','$repWord','$userid',NOW(),'[Forum] - Replay Content')") or die(mysql_error());  
		  }
		if($replycontent==NULL)
		{
		$userid = $_SESSION['curuser'];
		$topicid = $_GET['topicid'];
		$replycontent = $_POST['elm1'];
		$replyby = $_SESSION['us'];
		$datetime = date("F j, Y H:i:s");
		print '
		
		<script type="text/javascript">
		
		alert("Please complete the fields.");
		window.history.go(-1)

		</script>
		
		
		';
		
		}
		
		else {
		
		$insert = mysql_query("INSERT INTO tblfrreply (topicid,
												replycontent,
												replytime,
												replyby,
												replybyid) VALUES('$topicid',
												'$replycontent',
												'$datetime',
												'$replyby',
												'$userid')") or die (mysql_error());
		
		print '
		
		<script type="text/javascript">
		
		window.location = "viewtopic.php?topicid='.$topicid.'";
		</script>
		
		
		';
		
		}


}




?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>Reply to Topic</title>

	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
    	<link type="text/css" href="../css/demo.css" rel="stylesheet" />
          <link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />
        
</head>
<body>

 <div id="page">
<div id="wrapper">
        
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
    <p> </p>
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left" class="date"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
    </div>
    <div id="ex">
    </div>
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
       <!-- <div id="chef_ind"> open chef -->
        <div id="welcome"> <!--open welcome -->
               <!-- <h2 class="guilded"></h2> -->
        </div> <!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>

        </div>
        
     <!-- </div>close left -->
      <!--</div>close left -->

      <div id="content"> 
      <div class="desriptionHeader"> <!--open right-->
      <div id="container">
    
         <div class="post3_students"><h2>Forum</h2> </div>
      
            <div class="desriptionHeader"> <!--open right-->
       <div class="postbg1"><!--open booking -->
        <div align="center" class="mainbox">
<form id="form2" name="form2" method="post" action="">
                    <table width="655" border="0" id="cform">
                    <tr>
                        <td colspan="6">
                    <b>Forum</b><img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="<? print $catlink; ?>.php"><? print $catego; ?></a>  <img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="viewtopic.php?topicid=<? print $topicid; ?>"><? print $title; ?></a> <img width="25" height="15" border="0" src="../images/arrow.png"> <strong><a class="siteloc" href="#">Reply</a></strong>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" background="catbg.png" colspan="5" class="cat"><? print $title; ?></td>
                    </tr>
                    <tr>
                  <td height="23" colspan="2" class="label">POST A NEW REPLY</td>
                	</tr>
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td class="extra">Title: <input name="title" readonly="readonly" type="text" id="title" size="113" value="<? print $title; ?>" /></td>
                      </tr>
                      <tr>
                        <td colspan="2">&nbsp; </td>
                      </tr>
                      <tr>
                        <td colspan="2"><label>
                          <textarea name="elm1" id="elm1" rows="15" cols="80" style="width: 70%"><? print $replycontent; ?></textarea>
                        </label></td>
                      </tr>
                      <tr>
                        <td colspan="2" align="center"><label>
                            <input value='Back' type='button' id='btnb' onclick='history.go(-1); return false;' /> 
                            </label> 
                            <label> <input type="submit" name="create" id="create" value="Submit" />
                        </label></td>
                      </tr>
                    </table>
                        </form>  
                      </div>   
</div><!--close booking -->
   </div><!--close desc -->
   
          
     				
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->


</body>
</html>



	

